<template>
    <div>
        <table class="table">
            <tbody class="table">
                <tr>
                    <td><span style="color: red;">*</span>账号</td>
                    <td>
                        <input type="text" v-model="data.num">
                    </td>
                </tr>
                <tr>
                    <td><span style="color: red;">*</span>密码</td>
                    <td>
                        <input type="password" v-model="data.pwd">
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="登录" @click="login">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { useStore } from '@/stores/user';
import axios from 'axios';
import { ref } from 'vue';
import { useRouter } from 'vue-router';




const data=ref({
    num:'',
    pwd: ''
})

const router=useRouter();
const use=useStore();
const login=()=>{
    if(data.value.num==""){
        alert("账号不能为空");
        return;
    }
    if(data.value.pwd==""){
        alert("密码不能为空");
        return;
    }

    axios.get("https://localhost:7017/api/Login/LoginInfo",{params:data.value}).then(res=>{
        if(res.data.mid==-1){
            alert("账号不存在");
            return;
        }
        if(res.data.mid==-2){
            alert("密码错误");
            return;
        }
        if(res.data.mid>0){
            alert("登录成功");
            use.someState.islogin=true;
            router.push({
                path:'/MaShowView'
            })
            return;
        }else{
            alert("登陆失败")
        }
    })
}

</script>

<style scoped>

</style>